<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>类型检测与转换</title>
</head>
<body>
    <div>klsdflskjkkf</div>
    <div>435342636534</div>
    <script>
        let arr = [1,2,3,4,5,6];
        console.log(Array.isArray(arr));//检测变量是否为数组

        // 将数组转化为字符串
        console.log(typeof String(arr));
        console.log(typeof (arr).toString());
        console.log(typeof arr.join(','));


        // 网站的请求参数
        let hd = [1,2,3].join('-');
        console.log(location.href + '?id=' + hd);


        // 将字符串转化成数组
        let xiasnn = 'xiasnn';
        console.log(xiasnn.split(''));
        console.log(Array.from(xiasnn));// 有length属性的变量都可以用Array.from

        let obj = {
            name : 'fkdflds',
            age : 45,
            length : 3
        }
        console.log(Array.from(obj));// 有length属性的变量都可以用Array.from


        //将dom节点转化为数组
        let divs = document.querySelectorAll('div');
        let divarr = Array.from(divs);
        console.log(divarr);

        console.log(Array.from(divs,function(item){
            item.style.backgroundColor = 'red';
            return item;
        }));
    </script>
</body>
</html>